﻿using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;

namespace MCUPic.Core.Functions.BulkConvert
{
    public class BulkConvert : IBulkConvert
    {
        BulkConvertParam Param;
        BinGen BinGen;
        PicConverter PicCon;

        public BulkConvert(BulkConvertParam Param)
        {
            this.Param = Param;
            BinGen = new BinGen(this.Param.OutputPath);
            PicCon = new PicConverter();
        }

        public void Start()
        {
            string[] objFiles = Param.Files;

            // 生成Cache
            for (int index = 0; index < objFiles.Length; index++)
            {
                /* 缩放 */
                Bitmap srcbmp = PicCon.Scale(new Bitmap(objFiles[index]), Param.ScreenSize, Param.ScaleMode);
                /* 剪切 */
                srcbmp = PicCon.DrawBmp(srcbmp, Param.ScreenWindow, Param.PixelFormat);
                //srcbmp.Save("D:\\Users\\18511\\Desktop\\new.bmp");//debug
                BinGen.AddCache(srcbmp, Param.OutputOption[3]);
            }
            // 生成文件
            if (Param.OutputOption[0]) BinGen.GenCCodeFromCache(Param);
            if (Param.OutputOption[1]) BinGen.GenBinFromCache();
            if (Param.OutputOption[2]) BinGen.GenBinFromCache();

            BinGen.Release();
        }
    }
}
